package fr.waitandsee.tools;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class BitmapFactoryAdapter {
	
	public static Bitmap decodeResource(Context context, int id) {
	    //Decode image size
		BitmapFactory.Options options = new BitmapFactory.Options();
		options.inJustDecodeBounds = true;
		BitmapFactory.decodeResource(context.getResources(), id, options);
		//The new size we want to scale to
		final int REQUIRED_SIZE=70;
		//Find the correct scale value. It should be the power of 2.
		int scale=1;
		while(options.outWidth/scale/2>=REQUIRED_SIZE && options.outHeight/scale/2>=REQUIRED_SIZE) {
			scale*=2;
		}
		//Decode with inSampleSize
		BitmapFactory.Options options2 = new BitmapFactory.Options();
		options2.inSampleSize=scale;
		return BitmapFactory.decodeResource(context.getResources(), id, options2);
	}

}
